
/**
 * leftNavBar vuex
 */
// import posts from '@/plugins/request'
import storage from '@/plugins/localStorage'


const state = {
  pageTree: {},
  activeIndex: '1-1'
}

const getters = {
  //获取左侧菜单栏 path 信息
  getPageTree: state => {
    return [
      {
        canDo: [],
        id: "137",
        name: "实时监控",
        orderNum: 1,
        type: "0",
        url: "/home",
      },
      {
        canDo: [],
        id: "144",
        name: "实验室管理",
        orderNum: 2,
        type: "0",
        url: "/laboratory",
        children: [
          {
            canDo: [],
            id: "145",
            index: "4-1",
            name: "检测设备管理",
            orderNum: 1,
            parentId: "144",
            type: "0",
            url: "/laboratory/equipment",
          },
          {
            canDo: [],
            id: "146",
            index: "4-2",
            name: "耗材管理",
            orderNum: 1,
            parentId: "144",
            type: "0",
            url: "/laboratory/consumables",
          },
          {
            canDo: [],
            id: "147",
            index: "4-3",
            name: "环境管理",
            orderNum: 1,
            parentId: "144",
            type: "0",
            url: "/laboratory/environment",
          },
          {
            canDo: [],
            id: "148",
            index: "4-4",
            name: "门禁管理",
            orderNum: 1,
            parentId: "144",
            type: "0",
            url: "/laboratory/entrance",
          },
          {
            canDo: [],
            id: "149",
            index: "4-5",
            name: "能耗管理",
            orderNum: 1,
            parentId: "144",
            type: "0",
            url: "/laboratory/energy",
          },
          {
            canDo: [],
            id: "150",
            index: "4-6",
            name: "视频监控",
            orderNum: 1,
            parentId: "144",
            type: "0",
            url: "/laboratory/video",
          },
          {
            canDo: [],
            id: "151",
            index: "4-7",
            name: "审核管理",
            orderNum: 1,
            parentId: "144",
            type: "0",
            url: "/laboratory/examine",
          }
        ]
      },
      {
        canDo: [],
        id: "152",
        name: "事件管理",
        orderNum: 2,
        type: "0",
        url: "/event",
        children: [
          {
            canDo: [],
            id: "153",
            index: "4-1",
            name: "事件列表",
            orderNum: 1,
            parentId: "152",
            type: "0",
            url: "/event/eventList",
          },
        ]
      },
      {
        canDo: [],
        id: "154",
        name: "维护维修",
        orderNum: 2,
        type: "0",
        url: "/maintain",
        children: [
          {
            canDo: [],
            id: "155",
            index: "4-1",
            name: "维护维修",
            orderNum: 1,
            parentId: "154",
            type: "0",
            url: "/maintain/maintainList",
          },
        ]
      }
    ]
    // if(state.pageTree.length) {
    //   return state.pageTree
    // }else if(storage.get('userInfo')) {
    //   return JSON.parse(storage.get('userInfo')).trees.children
    // }else {
    //   return []
    // }
  },
  getActiveIndex: state => state.activeIndex
}

const actions = {}

const mutations = {
  updatePageTree(state, data) {
    state.pageTree = data
  },
  changeActiveIndex(state, index) {
    state.activeIndex = index
  }
}
export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
